import {reqGetGoodDetailInfoData} from '@/api/index'

const state = {
  goodDetailInfo: {}//详情数据
}
const getters = {
// 图片上方的分类条
  categoryView(state){
    return state.goodDetailInfo.categoryView || {}
  },
// 商品
  skuInfo(state){
    return state.goodDetailInfo.skuInfo || {}
  },
  // 平台属性(嵌套数组)
  spuSaleAttrList(state){
    return state.goodDetailInfo.spuSaleAttrList || []
  },
}
const mutations = {
  // 1. 存储详情数据
  SAVE_GOOD_DETAIL_INFO_DATA(state,goodDetailInfo){
    state.goodDetailInfo = goodDetailInfo
  }
}
const actions = {
  //1. 获取商品详情数据
  async getGoodDetailInfoData({commit},id){
    const result = await reqGetGoodDetailInfoData(id)
    if (result.code === 200) {
      commit('SAVE_GOOD_DETAIL_INFO_DATA',result.data)
    } else {
      console.log(result.message);
    }
  }
}
export default {
  namespaced: true, // 设置命名空间 用来区分不同的模块
  state,
  actions,
  mutations,
  getters,
};
